package trystero.lib.util;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;

public class StreamUtils
{
   /*
    * Useful for dealing with android's org.json package, which
    * will only accept a string to build off. Test the newer
    * version which accepts a Reader, and we could do without this.
    */
   public static String slurp(InputStream input) 
   {
      String slurp = "";

      BufferedReader reader = new BufferedReader(new InputStreamReader(input));
   
      while(true)
      {
         String line;
         try
         {
            line = reader.readLine();
         }
         catch(Exception e)
         {
            return slurp;
         }
            
         if(line == null)
            break;

         slurp += line + "\n";
      }

      return slurp;
   }
}
